<?php

$first_name 	= $this->formText('first_name',$this->Item['first_name'],array('class'=>'form-control', 'placeholder' => 'First name'));
$last_name 		= $this->formText('last_name',$this->Item['last_name'],array('class'=>'form-control', 'placeholder' => 'Last name'));
$email 			= $this->formText('email',$this->Item['email'],array('class'=>'form-control', 'placeholder' => 'Email'));
$password 		= $this->formPassword('password',$this->Item['password'],array('class'=>'form-control', 'placeholder' => 'Password'));
$re_password 	= $this->formPassword('re_password',$this->Item['re_password'],array('class'=>'form-control', 'placeholder' => 'Re-password'));
$birthday	    = $this->formText('birthday',$this->Item['birthday'],array('class'=>'form-control', 'placeholder' => 'Birthday'));
$sign	 	   	= $this->formTextarea('sign',$this->Item['sign'],array('class'=>'form-control', 'rows' => 8, 'placeholder' => 'Sign'));
$avatar   		= $this->formFile('avatar',array('class'=>'form-control file-inputs', 'data-filename-placement' => 'inside'));


$linkPost = $this->cmsUrl(array('action'=>'user-register'));
?>
<div class="row">
    <div class="box">
    	<div class="col-md-10 col-md-offset-1 list-error" id="list-error" style="display: none"></div>
    	<div class="clr"><h4 style="margin: 0px 0px 20px 0px; text-align: center">CLIENT REGISTER</h4></div>
		<form class="form-horizontal" role="form" id="appForm" name="appForm" action="<?php echo $linkPost?>" method="post" enctype="multipart/form-data" >
			<div class="form-group col-md-6 frm-input">
	        	<label class="col-md-4 col-xs-3 control-label">FIRST NAME</label>
			     <div class="col-sm-4 column-input-4">
					<?php echo $first_name?>
				</div>
	      	</div>
	      	<div class="form-group col-md-6 frm-input">
	        	<label class="col-md-4 col-xs-3 control-label">LAST NAME</label>
			     <div class="col-sm-4 column-input-4">
					<?php echo $last_name?>
				</div>
	      	</div>
	      	<div class="clr"></div>
	      	<div class="form-group col-md-6 frm-input">
	        	<label class="col-md-4 col-xs-3 control-label">AVATAR</label>
			     <div class="col-sm-4 column-input-4">
					<?php echo $avatar?>
				</div>
	      	</div>
	      	<div class="clr"></div>
	      	
	      	<div class="form-group col-md-6 frm-input">
	        	<label class="col-md-4 col-xs-3 control-label">EMAIL</label>
			     <div class="col-sm-4 column-input-4">
					<?php echo $email?>
				</div>
	      	</div>
	      	<div class="clr"></div>
	      	<div class="form-group col-md-6 frm-input">
	        	<label class="col-md-4 col-xs-3 control-label">BIRTHDAY</label>
			     <div class="col-sm-4 column-input-4">
					<?php echo $birthday?>
				</div>
	      	</div>
	      	<div class="clr"></div>
	      	
	      	<div class="form-group col-md-6 frm-input">
	        	<label class="col-md-4 col-xs-3 control-label">PASSWORD</label>
			     <div class="col-sm-4 column-input-4">
					<?php echo $password?>
				</div>
	      	</div>
	      	<div class="clr"></div>
	      	<div class="form-group col-md-6 frm-input">
	        	<label class="col-md-4 col-xs-3 control-label">RE-PASS</label>
			     <div class="col-sm-4 column-input-4 bootstrap-timepicker"">
					<?php echo $re_password?>
				</div>
	      	</div>
	      	<div class="clr"></div>
	      	<div class="form-group col-md-12 frm-input">
	        	<label class="col-md-2 col-xs-3 control-label">SIGN</label>
			     <div class="col-md-10 col-xs-8" id="wrap_sign">
					<?php echo $sign?>
				</div>
	      	</div>
	      	
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-9" style="text-align: right">
					<button type="submit" id="btn-bumit" class="btn btn-default bg-blue">SUBMIT</button>
				</div>
			</div>
		</form>
	</div>
	<div class="icon-loading"></div>
</div>
<?php
$linkReturn = $this->cmsUrl(array('action' => 'add-new-item'));
?>
<script>
	$(function(){
		$(".fancybox-inner").niceScroll();
		$('#birthday').datepicker({ format: 'mm/dd/yyyy',});
		$('#btn-bumit').click(function(){
			$('.icon-loading').show();
		})
		$('#appForm').ajaxForm({ 
	        // dataType identifies the expected content type of the server response 
	        dataType:  'json', 
	 
	        // success identifies the function to invoke when the server response 
	        // has been received 
	        success: function(data){
	        	$('.icon-loading').hide();
	        	$('form[name="appForm"] div.frm-input').addClass('has-success');
	    		$('#list-error').html('').hide();
				if(data.type == "error"){
					for(var x in data.msg){
						$('input#' + x).parent().parent().addClass('has-error');
						$('input#' + x).parent().find('span.glyphicon').removeClass('glyphicon-ok').addClass('glyphicon-remove');
						$('#list-error').append('<div class="alert alert-danger" id="list_device_alert"><strong>' + data.msg[x] + '</strong></div>');
					}
					$('#list-error').fadeIn();
				}else{
                    $.get("<?php echo $linkReturn?>", function(data){
                        $.fancybox({
                            maxWidth	: '850',
                            minWidth	: '240',
                            scrolling	: 'yes',
                            content : data
                        })
                    });

					$('form[name="appForm"] span.tag').remove();
					$('form[name="appForm"] div.frm-input').removeClass('has-success').removeClass('has-error');
					$('span.form-control-feedback').remove();
					$('#appForm')[0].reset();
					$('#list-error').html('<div class="alert alert-success" id="list_device_alert"><strong>Congratulation! Thank for your registration</strong></div>').fadeIn().delay(3000).fadeOut();
				}
	        } 
	    }); 
	})
	
</script>
